# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/addison_defconfig

pkgname=linux-motorola-addison
pkgver=3.18.120
pkgrel=0
pkgdesc="motorola Motorola Moto Z Play kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="motorola-addison"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev flex openssl-dev perl dtbtool"

# Source
_repository="artxplay_msm8953_addison"
_commit="c2dcd33239fb09ba0f322ee6bfe3a8f1f6329c4c"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/KB-E/$_repository/archive/$_commit.tar.gz
	$_config
	wireguard.patch
	gcc10-extern_YYLOC_global_declaration.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"

	# Master DTB (deviceinfo_bootimg_qcdt)
	dtbTool -p scripts/dtc/ -o "$_outdir/arch/$_carch/boot"/dt.img "$_outdir/arch/$_carch/boot/"
	install -Dm644 "$_outdir/arch/$_carch/boot"/dt.img "$pkgdir"/boot/dt.img
}

sha512sums="5943439e2951c8857a3a41c806cd6f607c78872648d7826c1c4aa67b1c6bfb9500516899e9f7fd73bc7bf8e746ccb0fdb0712e047e8e53d28930121e6fe93cc4  linux-motorola-addison-c2dcd33239fb09ba0f322ee6bfe3a8f1f6329c4c.tar.gz
aa6aff7d85ed811389169df4b0c770bbc04be3a040cb609c28e1b05af0d4ecb69f505b0480659645d1c78d2c523a18ca4184c9156d22c8b5b4a6f27364c4bddc  config-motorola-addison.aarch64
638c4b9887f14f0c6cbbd7bb042cc9ef142795a3e62e4f2e5ef8c4489f2d1129d0aa3d0ee1c20fdd8c08b56bee1405aca4fb65a882124b6cc3c31fd2bc90a8ba  wireguard.patch
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb  gcc10-extern_YYLOC_global_declaration.patch"
